local chenglue = fk.CreateSkill {

  name = "joy__chenglue",

  tags = {  },

}



chenglue:addEffect("active", {
  name = "joy__chenglue",
  anim_type = "offensive",
  prompt = "#joy__xuyou-active",
  can_use = function(self, player)
    return player:usedSkillTimes(chenglue.name, Player.HistoryPhase) < 1
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return false
  end,
  on_use = function(self, room, effect)
    local from = effect.from
    from:drawCards(1, chenglue.name)
    local cardsDiscarded = table.filter(room:askForDiscard(from, 1, 1, false, chenglue.name, false), function(id)
      return Fk:getCardById(id).suit < Card.NoSuit
    end)
    if #cardsDiscarded > 0 then
      local suitsToRecord = table.map(cardsDiscarded, function(id)
        return Fk:getCardById(id):getSuitString(true)
      end)
      local suitsRecorded = type(from:getMark("@joy__chenglue-turn")) == "table" and from:getMark("@joy__chenglue-turn") or {}
      for _, suit in ipairs(suitsToRecord) do
        table.insertIfNeed(suitsRecorded, suit)
      end
      room:setPlayerMark(from, "@joy__chenglue-turn", suitsRecorded)
    end
  end,
})

chenglue:addEffect("targetmod", {
  name = "#joy__chenglue_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and player:getMark("@joy__chenglue-turn") ~= 0 and table.contains(player:getMark("@joy__chenglue-turn"), "log_"..card:getSuitString())
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player:getMark("@joy__chenglue-turn") ~= 0 and table.contains(player:getMark("@joy__chenglue-turn"), "log_"..card:getSuitString())
  end,
})

return chenglue